package _09练习;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

public class Exercise13 {
	public static void main(String ages[]) throws IOException, FileNotFoundException {
		// 八、 转换流
				// 13.
				// 	1. 准备一个gbk编码的txt文件
				// 	2. 使用转换流 读取出这个txt的内容
				
		Reader r = new InputStreamReader(new FileInputStream("e:/abc.txt"),"gbk");
		 
		// 2. 读取
		char[] buf = new char[1024];
		int len = 0;
		len = r.read(buf);
		String msg = new String(buf,0,len);
		System.out.println(msg);
		
		// 3. 关闭
		r.close();
				// 九、 读取配置文件
				
				// 13. 准备一个配置文件stus.txt内容如下
				// id=101
				// name=zhangsan
				// age=18
				// 使用Properties类读取出id、name、age的值
		testWrite();
		testRead() ;
		
	}
	private static void testWrite() throws FileNotFoundException, IOException {
		//1
		
		Properties p = new Properties();
		
		// 2.
		p.put("id", "101");
		p.put("name", "zhangsan");
		p.put("age", "18");
		
		
		// 3.
		
		p.store(new FileOutputStream("stus.txt"),"aaa");
		
		
		
		
	}
	private static void testRead() throws FileNotFoundException, IOException {

		// 1. 
		Properties p = new Properties();
		p.load(new FileInputStream("stus.txt"));
		
		// 2. 
		System.out.println(p.getProperty("id"));
		System.out.println(p.getProperty("name"));
		System.out.println(p.getProperty("age"));
		
	}
}

